﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcUI.Filter
{
    public class RoleFilter:FilterAttribute,IAuthorizationFilter
    {
        public string Role { get; set; }
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            HttpContextBase hcb = filterContext.HttpContext;
            if (!Convert.ToBoolean(HttpContext.Current.Session["Verified"]))
            {
                hcb.Response.Redirect("~/Error/Index");
            }
            else
            {
                if (Role != HttpContext.Current.Session["Role"].ToString())
                {
                  
                    hcb.Response.Redirect("~/Error/Index");
                }
            }
        }
    }
}